package com.knife.oauth.api.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.knife.common.utils.Results;
import com.knife.oauth.app.service.IamRoleService;
import com.knife.oauth.domain.entity.IamRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 角色(IamRole)表控制层
 *
 * @author tianhao.luo@hand-china.com
 * @since 2025-08-13 14:19:30
 */

@RestController("iamRoleController.v1")
@RequestMapping("/v1/{organizationId}/iam-roles")
public class IamRoleController {
    @Autowired
    private IamRoleService iamRoleService;

    @GetMapping
    public ResponseEntity<Page<IamRole>> selectRolePage(@PathVariable Long organizationId, IamRole iamRole, Page<IamRole> pageRequest) throws IllegalAccessException {
        iamRole.setTenantId(organizationId);
        return Results.success(iamRoleService.selectRolePage(pageRequest, iamRole));
    }

    /**
     * 保存或更新
     */
    @PostMapping
    public IamRole saveOrUpdateRole(@PathVariable Long organizationId, @RequestBody IamRole iamRole) {
        iamRole.setTenantId(organizationId);
        return iamRoleService.saveOrUpdateRole(iamRole);
    }
    /**
     * 删除
     */
    @DeleteMapping
    public IamRole deleteRole(@PathVariable Long organizationId, @RequestBody IamRole iamRole) {
        iamRole.setTenantId(organizationId);
        return iamRoleService.deleteRole(iamRole);
    }
}

